<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Class error_with_option_name</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../program_options/reference.html#header.boost.program_options.errors_hpp" title="Header &lt;boost/program_options/errors.hpp&gt;">
<link rel="prev" href="reading_file.html" title="Class reading_file">
<link rel="next" href="multiple_values.html" title="Class multiple_values">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="reading_file.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../program_options/reference.html#header.boost.program_options.errors_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="multiple_values.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.program_options.error_with_option_name"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class error_with_option_name</span></h2>
<p>boost::program_options::error_with_option_name</p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../program_options/reference.html#header.boost.program_options.errors_hpp" title="Header &lt;boost/program_options/errors.hpp&gt;">boost/program_options/errors.hpp</a>&gt;

</span>
<span class="keyword">class</span> <a class="link" href="error_with_option_name.html" title="Class error_with_option_name">error_with_option_name</a> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">program_options</span><span class="special">::</span><span class="identifier">error</span> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
  <span class="comment">// <a class="link" href="error_with_option_name.html#boost.program_options.error_with_option_nameconstruct-copy-destruct">construct/copy/destruct</a></span>
  <a class="link" href="error_with_option_name.html#idp65312496-bb"><span class="identifier">error_with_option_name</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> <span class="special">=</span> <span class="string">""</span><span class="special">,</span> 
                         <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> <span class="special">=</span> <span class="string">""</span><span class="special">,</span> <span class="keyword">int</span> <span class="special">=</span> <span class="number">0</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="error_with_option_name.html#idp67248704-bb"><span class="special">~</span><span class="identifier">error_with_option_name</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="error_with_option_name.html#idp61704800-bb">public member functions</a></span>
  <span class="keyword">void</span> <a class="link" href="error_with_option_name.html#idp61704976-bb"><span class="identifier">set_substitute</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="error_with_option_name.html#idp61706288-bb"><span class="identifier">set_substitute_default</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">,</span> 
                              <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="error_with_option_name.html#idp65307184-bb"><span class="identifier">add_context</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="error_with_option_name.html#idp65308656-bb"><span class="identifier">set_prefix</span></a><span class="special">(</span><span class="keyword">int</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="error_with_option_name.html#idp65309376-bb"><span class="identifier">set_option_name</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <a class="link" href="error_with_option_name.html#idp65310656-bb"><span class="identifier">get_option_name</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="error_with_option_name.html#idp65311072-bb"><span class="identifier">set_original_token</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span> <a class="link" href="error_with_option_name.html#idp65311792-bb"><span class="identifier">what</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="error_with_option_name.html#idp67249040-bb">protected member functions</a></span>
  <span class="keyword">void</span> <a class="link" href="error_with_option_name.html#idp67249216-bb"><span class="identifier">substitute_placeholders</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="error_with_option_name.html#idp67250176-bb"><span class="identifier">replace_token</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <a class="link" href="error_with_option_name.html#idp67251200-bb"><span class="identifier">get_canonical_option_name</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <a class="link" href="error_with_option_name.html#idp67631024-bb"><span class="identifier">get_canonical_option_prefix</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="error_with_option_name.html#boost.program_options.error_with_option_namepublic-data-members">public data members</a></span>
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <a class="link" href="error_with_option_name.html#boost.program_options.error_with_option_name.m_error_template"><span class="identifier">m_error_template</span></a><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="idp120428016"></a><h2>Description</h2>
<p>Base class for most exceptions in the library.</p>
<p>Substitutes the values for the parameter name placeholders in the template to create the human readable error message</p>
<p>Placeholders are surrounded by % signs: example% Poor man's version of boost::format</p>
<p>If a parameter name is absent, perform default substitutions instead so ugly placeholders are never left in-place.</p>
<p>Options are displayed in "canonical" form This is the most unambiguous form of the *parsed* option name and would correspond to option_description::format_name() i.e. what is shown by print_usage()</p>
<p>The "canonical" form depends on whether the option is specified in short or long form, using dashes or slashes or without a prefix (from a configuration file) </p>
<div class="refsect2">
<a name="idp120429760"></a><h3>
<a name="boost.program_options.error_with_option_nameconstruct-copy-destruct"></a><code class="computeroutput">error_with_option_name</code> 
        public
       construct/copy/destruct</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem"><pre class="literallayout"><a name="idp65312496-bb"></a><span class="identifier">error_with_option_name</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> template_<span class="special">,</span> 
                       <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> option_name <span class="special">=</span> <span class="string">""</span><span class="special">,</span> 
                       <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> original_token <span class="special">=</span> <span class="string">""</span><span class="special">,</span> 
                       <span class="keyword">int</span> option_style <span class="special">=</span> <span class="number">0</span><span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem">
<pre class="literallayout"><a name="idp67248704-bb"></a><span class="special">~</span><span class="identifier">error_with_option_name</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>gcc says that throw specification on dtor is loosened without this line </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="idp120442640"></a><h3>
<a name="idp61704800-bb"></a><code class="computeroutput">error_with_option_name</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp61704976-bb"></a><span class="identifier">set_substitute</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> parameter_name<span class="special">,</span> 
                    <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> value<span class="special">)</span><span class="special">;</span></pre>
<p>Substitute parameter_name-&gt;value to create the error message from the error template </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp61706288-bb"></a><span class="identifier">set_substitute_default</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> parameter_name<span class="special">,</span> 
                            <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> from<span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> to<span class="special">)</span><span class="special">;</span></pre>
<p>If the parameter is missing, then make the from-&gt;to substitution instead </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp65307184-bb"></a><span class="identifier">add_context</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> option_name<span class="special">,</span> 
                 <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> original_token<span class="special">,</span> <span class="keyword">int</span> option_style<span class="special">)</span><span class="special">;</span></pre>
<p>Add context to an exception </p>
</li>
<li class="listitem"><pre class="literallayout"><span class="keyword">void</span> <a name="idp65308656-bb"></a><span class="identifier">set_prefix</span><span class="special">(</span><span class="keyword">int</span> option_style<span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp65309376-bb"></a><span class="identifier">set_option_name</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> option_name<span class="special">)</span><span class="special">;</span></pre>
<p>Overridden in <code class="computeroutput"><a class="link" href="error_with_no_option_name.html" title="Class error_with_no_option_name">error_with_no_option_name</a></code> </p>
</li>
<li class="listitem"><pre class="literallayout"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <a name="idp65310656-bb"></a><span class="identifier">get_option_name</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="keyword">void</span> <a name="idp65311072-bb"></a><span class="identifier">set_original_token</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> original_token<span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span> <a name="idp65311792-bb"></a><span class="identifier">what</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Creates the error_message on the fly Currently a thin wrapper for substitute_placeholders() </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="idp120480112"></a><h3>
<a name="idp67249040-bb"></a><code class="computeroutput">error_with_option_name</code> protected member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp67249216-bb"></a><span class="identifier">substitute_placeholders</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> error_template<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Makes all substitutions using the template </p>
</li>
<li class="listitem"><pre class="literallayout"><span class="keyword">void</span> <a name="idp67250176-bb"></a><span class="identifier">replace_token</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> from<span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&amp;</span> to<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <a name="idp67251200-bb"></a><span class="identifier">get_canonical_option_name</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Construct option name in accordance with the appropriate prefix style: i.e. long dash or short slash etc </p>
</li>
<li class="listitem"><pre class="literallayout"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <a name="idp67631024-bb"></a><span class="identifier">get_canonical_option_prefix</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
</ol></div>
</div>
<div class="refsect2">
<a name="idp120497312"></a><h3>
<a name="boost.program_options.error_with_option_namepublic-data-members"></a><code class="computeroutput">error_with_option_name</code> 
        public
       public data members</h3>
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<pre class="literallayout"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <a name="boost.program_options.error_with_option_name.m_error_template"></a><span class="identifier">m_error_template</span><span class="special">;</span></pre>
<p>template with placeholders </p>
</li></ol></div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2004 Vladimir Prus<p>Distributed under the Boost Software License, Version 1.0.
      (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at 
      <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="reading_file.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../program_options/reference.html#header.boost.program_options.errors_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="multiple_values.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
